package com.sos.flex.data.adapters
{
	import com.sos.core.cards.Collection;
	import com.sos.core.cards.Deck;
	import com.sos.flex.data.FlexCollection;
	import com.sos.flex.data.FlexDeck;

	public class CollectionAdapter
	{
		
		public static function updateFlexCollection(source:Collection, destination:FlexCollection):void
		{
			// Clears the source
			destination.clear();
			// Copy cards
			for (var i:int = 0; i < source.cardCount; i++)
			{
				destination.cards.addItem(source.cards[i].clone());
			}
			// Copy decks
			for (var j:int = 0; j < source.decksCount; j++)
			{
				var deck:Deck = source.decks[j];
				// Add the deck adapted from the original Deck
				destination.addDeck( DeckAdapter.toFlexDeck(deck, destination) );
			}
			// Active deck
			destination.activeDeck = destination.getDeckById( source.activeDeck.id );			
			// 'Loaded' flag forcing
			if (source.loaded) destination.forceLoaded();
		}

		public static function toFlexCollection(collection:Collection):FlexCollection
		{
			var flexCollection:FlexCollection = new FlexCollection();
			updateFlexCollection(collection, flexCollection);
			return flexCollection;
		}
		
	}
}